package com.example.mapper;

import com.example.domain.User;
import com.example.domain.UserLeaveDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author 符整国
 * @version 1.0
 */
@Mapper
public interface UserMapper{

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User getByUsername(String username);


    /**
     * 根据用户名修改密码
     * @param username
     * @param newPassword
     */
    @Update("update user set password = #{newPassword} where username = #{username}")
    void updatePasswordByUsername(String username, String newPassword);

    /**
     * 添加请假信息
     * @param userLeaveDTO
     */
    @Insert("insert into leave_info(user_id,leave_begin,leave_end,leave_state,leave_remark,reason) values (" +
            "#{userId},#{leaveBegin},#{leaveEnd},#{leaveState},#{leaveRemark},#{reason})")
    void insertLeave(UserLeaveDTO userLeaveDTO);

    /**
     * 根据ID查询用户信息
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User getById(Integer id);
}
